<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.sci99.ex.model.*"%>
<%@ page import="com.sci99.ex.util.*"%>
<%@ page import="org.apache.log4j.Logger"%>
<%@ page import="org.apache.ibatis.session.SqlSession"%>
<%@ page
	import="org.springframework.security.core.userdetails.UserDetails"%>
<%@ page
	import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Logger log = Logger.getLogger(this.getClass());
Employee user = UserUtil.getUser();
SqlSession s  = MyBatisUtil.getMySqlSession();
String key = new String(
		request.getParameter("k").getBytes("ISO-8859-1"), "UTF-8");
log.error(key);
Map m = new HashMap(2,1);
m.put("name",key);
List rs = s.selectList("getCourse", m);
List ml = new ArrayList();
for(Object r:rs){
	Map mm = new HashMap();
	Course c = (Course)r;
	mm.put("id",c.getId());
	mm.put("name",c.getName());
	mm.put("lecturer",c.getLecturer());
	mm.put("period",c.getPeriod());
	ml.add(mm);
}

s.close();
request.setAttribute("rs", ml);
request.setAttribute("key", key);
request.setAttribute("size", ml.size());
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>课程搜索页</title>
<script src="public/jquery-1.8.3.min.js"></script>
<link href="styles/base.css" rel="stylesheet" type="text/css" />
<link href="styles/common.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
    function schCourse(){
        var kw = document.sch.k.value;
        if(kw == null || $.trim(kw).length == 0)
            return;
        window.location.href='search.jsp?k='+encodeURI(document.sch.k.value);
    }
    function addCourse(){
        var chk_value =[];    
        $('input[name="ca"]:checked').each(function(){    
            chk_value.push($(this).val());    
        });
        if(chk_value.length == 0)return;
        $.ajax({
            type: 'POST',
            url: 'opt',
            data: { 'act':'addCourse','course':chk_value.join(',')
            },
            success: function(data, textStatus, jqXHR){
                if(data.success){
                    alert('添加成功');
                    window.location.href='manage.jsp';
                }else{
                    alert('当前课程已添加,请勿重复添加');
                }
            },
            dataType:'json'
        });
    }
	$(function() {
        $("#chk_all").click(function(){
            //console.debug($(this).attr("checked"));
            $("input[name='ca']").prop("checked",$(this).prop("checked"));
        });
    });
</script>
</head>
<body>
    
    <div class="main_out">
        <div class="main_top">
            <a href=""></a> <span>人力资源培训服务热线：6091073 7071868</span>
        </div>
        <div class="clear"></div>
        <div class="nav">
            <ul class="nav_l">
                <li><a href="index.jsp">首&nbsp;&nbsp;页</a></li>
                <li><a href="manage.jsp">课程管理</a></li>
                <!--li><a href="search.jsp">课程搜索</a></li -->
                <!--li><a href="add.jsp">课程添加</a></li -->
                <!--li><a href="video.jsp">视频播放</a></li -->
                <!--li><a href="login.jsp">登录页</a></li -->
            </ul>
            <div class="nav_r">
                <a href="j_spring_security_logout">退出登录</a>
            </div>
        </div>
    </div>
    <div class="main"><form name="sch">
      <div class="head3 mt">
        <span>当前位置：<a href="index.jsp">卓创网络学院</a> &gt;&gt; <a href="manage.jsp">课程管理</a> &gt;&gt; 课程添加</span>
        <h2><input name="k" type="text" class="searchinput" /><input name="" type="button" class="buttoninput" style="cursor:pointer;" onclick="schCourse()"/></h2>
      </div></form>
      <form id="form1">
      <div class="content">
        <div class="result">
          <span>您搜索的关键字为：<b><c:out value="${key}" /></b>  共为您找到<c:out value="${size}" />个课程</span>
          <a href="manage.jsp">返回课程列表</a>
        </div>
        <div class="head">
          <span>&nbsp;</span>
        </div>
        <div class="content1">
          <table cellspacing="0" class="tab_my">
            <thead>
            <tr>
              <th width="45">[选择]</th>
              <th>[课程名称]</th>
              <th width="45">[课时]</th>
              <th width="55">[讲师]</th>
              <th width="45">&nbsp;</th>
              <th width="35">&nbsp;</th>
            </tr>
            </thead>
            <c:forEach items="${rs}" var="mp">
            <tr>
              <th><input name="ca" type="checkbox" value="${mp.id}" /></th>
              <td><c:out value="${mp.name}" /></td>
              <th><c:out value="${mp.period}" /></th>
              <td><c:out value="${mp.lecturer}" /></td>
              <td class="red">&nbsp;</td>
              <td></td>
            </tr>
            </c:forEach>
          </table>
        </div>
          <div class="add">
            <span><input id="chk_all" type="checkbox" value="" />全选</span>
            <a href="javascript:addCourse()"></a>
          </div>
        </div>
      </form>
      </div>
    <div class="foot_out mt">
      <div class="foot">Copyright &copy; 2004-2012 SCI99 Inc. All rights reserved.</div>
    </div>
</body>
</html>
